package com.sskj.mine.ui.activity;


import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.WebUrl;
import com.sskj.mine.presenter.MineNewsDetailActivityPresenter;
import com.zzhoujay.richtext.RichText;

import butterknife.BindView;

@Route(path = RConfig.MINE_NEWS_DETAIL)
public class MineNewsDetailActivity extends BaseActivity<MineNewsDetailActivityPresenter> {

    @BindView(R2.id.tvContent)
    TextView tvContent;
    @BindView(R2.id.llHead)
    LinearLayout llHead;
    String content;
    @Autowired
    String id;
    @Autowired
    String xieyi;
    @Autowired
    String walletXieyi;
    @BindView(R2.id.tvNewsTitle)
    TextView tvNewsTitle;
    @BindView(R2.id.tvTime)
    TextView tvTime;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mine_news_detail;
    }

    @Override
    public MineNewsDetailActivityPresenter getPresenter() {
        return new MineNewsDetailActivityPresenter();
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        if (!TextUtils.isEmpty(id)) {
            mPresenter.getContent(id);
        }
        if (!TextUtils.isEmpty(xieyi)) {
            setTitle(App.INSTANCE.getString(R.string.mine_mineProtocalActivity1_j));
            mPresenter.getXieyi();
        }
        if (!TextUtils.isEmpty(walletXieyi)) {
            setTitle(App.INSTANCE.getString(R.string.mine_mineProtocalActivity1_j));
            mPresenter.getXieyi();
        }


    }

    public void updateUI() {
        if (TextUtils.isEmpty(content)) {
            return;
        }
        RichText.from(content).into(tvContent);
    }

    public void updateContent(String data) {
        this.content = data;

        updateUI();
    }

    public void updateContent(WebUrl data) {
        this.content = data.getContent();
        llHead.setVisibility(View.VISIBLE);
        tvTime.setText(data.getDate());
        tvNewsTitle.setText(data.getTitle());

        updateUI();
    }


}
